// pages/hair/hair.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    optionList:['所有','选项1','选项2'],
    value:'所有',
    hhh:'',
    hideFlag: true,//true-隐藏  false-显示
    animationData: {},//

    backgroundImage:[],
    lists:[
      "理发","染发","烫发","接发","美容护理",
    ],
    
    videoUrl1: '',
    price:'',
    pricename:'',
    tony:'理发师1',
    imageU:'',
    time:'9:00-10:00',
    pay:[],
    logs1:[

    ],
    menhead:[
      {img:'../source/men2.jpg',text:"理发师1"},
      {img:'../source/men1.jpg',text:'理发师2'},
      {img:'../source/men3.jpg',text:'理发师3'},
      {img:'../source/men4.jpg',text:'理发师4'}
    ],
    timechose:[
      "9:00-10:00","10:00-11:00","11:00-12:00","12:00-13:00","13:00-14:00","14:00-15:00","15:00-16:00"
    ],

 
    indexId: 0,
    indexId1:0,
    indexId2:0,



  },

  /**
   * 组件的方法列表
   */
  methods: {
       fetchimg: function () {
      // 调用后端接口获取图片数据
   wx.request({
     url: 'http://localhost:8080/price', // 修改为你的后端接口地址
     success: (res) => {
       this.setData({
        logs1: res.data.data // 将后端返回的图片数据存储到 data 的 imgurl 数组中
       })
  
     },
     fail: (error) => {
       console.log(error)
     }
   })
     },
     jumptap1(e){
       console.log(e)
      let index = e.currentTarget.dataset.menuindex1
      console.log(index)  
       let that = this
       let time = that.data.timechose[index]
      console.log(that.data.timechose[index])
   
     
      that.setData({
        indexId1:index,
        time:time,

      })
      
    },
    jumptap(e){
      let index = e.currentTarget.dataset.menuindex
      console.log(e)
      let that = this
      that.setData({
        indexId:index
      })
      
    },
    tapchose(e){
      let index = e.currentTarget.dataset.menuindex2
      console.log(e)
      let that = this
      console.log(index)
      console.log(that.data.menhead[index].text)
      let tony = that.data.menhead[index].text
      that.setData({
        indexId2:index,
        tony:tony
      })
    },
    jumptopay:function () {
      let that = this
      that.setData({
        pay:[{
          time:that.data.time,
          price:that.data.price,
          pricename:that.data.pricename,
          tony:that.data.tony,
          imageU:that.data.imageU
        }]
      })
      console.log(this.data.pay)

      this.gogogo()
      this.hideModal()
    
      
    },
    gogogo:function () {
      wx.navigateTo({    
        url: '../pay/pay?payArray=' + encodeURIComponent(JSON.stringify(this.data.pay)),    
        success(res){    
          console.log("sss")    
        }
      })
    },
    
    bi:function(){
      wx.request({
        url: 'http://localhost:8086/getbi1?param1=classpath:static/source/&param2=http://localhost:8086/source/',
        method: 'GET',
        success: (res) => {
          console.log(res)
          console.log(res.data)
          const imageURL = res.data;
          
          this.setData({
            backgroundImage: imageURL,
          });
        },
        fail: (error) => {
          console.error('Error fetching image URL:', error);
        }
      });
 
    },
    fetchVideoUrl: function () {
      wx.request({
        url: 'http://localhost:8080/getV',
        success: (res) => {
          const dynamicVideoUrl = res.data; // 假设后端接口返回视频URL的字段为"url"
          this.setData({
            videoUrl1: dynamicVideoUrl
          });
        },
        fail: (error) => {
          console.log('请求视频URL失败', error);
        }
      });
    },
    onLoad:function(options){
      this.fetchVideoUrl();
      this.bi();
      this.fetchimg();
      var that = this
      wx.getSystemInfo({
        success:function(res){
          that.setData({
            winHeight:res.windowHeight
          })
        }
      })
    },

    getOption:function(e){
      var that = this;
      that.setData({
        value:e.currentTarget.dataset.value,
        hideFlag: true
      })
    },
    //取消
    mCancel: function () {
      var that = this;
      that.hideModal();
    },
   hhhh:function(e) {
    var hhh=e.currentTarget.dataset.hh
    console.log(e.currentTarget.dataset.hh.price)
    console.log(e.currentTarget.dataset.hh.name)
    let pricename= e.currentTarget.dataset.hh.name
    let price = e.currentTarget.dataset.hh.price
    let imageU = e.currentTarget.dataset.hh.imageURL
    console.log(e.currentTarget.dataset.hh); 
     this.showModal();
     this.setData({
       hhh:hhh,
       pricename:pricename,
       price:price,
       imageU:imageU

     })
   },
   
    // ----------------------------------------------------------------------modal
    // 显示遮罩层
    showModal: function () {
 
      var that = this;
      that.setData({
        hideFlag: false
      })
      // 创建动画实例
      var animation = wx.createAnimation({
        duration: 400,//动画的持续时间
        timingFunction: 'ease',//动画的效果 默认值是linear->匀速，ease->动画以低速开始，然后加快，在结束前变慢
      })
      this.animation = animation; //将animation变量赋值给当前动画
      var time1 = setTimeout(function () {
        that.slideIn();//调用动画--滑入
        clearTimeout(time1);
        time1 = null;
      }, 100)
    },
   
    // 隐藏遮罩层
    hideModal: function () {
      var that = this;
      var animation = wx.createAnimation({
        duration: 400,//动画的持续时间 默认400ms
        timingFunction: 'ease',//动画的效果 默认值是linear
      })
      this.animation = animation
      that.slideDown();//调用动画--滑出
      var time1 = setTimeout(function () {
        that.setData({
          hideFlag: true
        })
        clearTimeout(time1);
        time1 = null;
      }, 220)//先执行下滑动画，再隐藏模块
      
    },
    //动画 -- 滑入
    slideIn: function () {
      this.animation.translateY(0).step() // 在y轴偏移，然后用step()完成一个动画
      this.setData({
        //动画实例的export方法导出动画数据传递给组件的animation属性
        animationData: this.animation.export()
      })
    },
    //动画 -- 滑出
    slideDown: function () {
      this.animation.translateY(300).step()
      this.setData({
        animationData: this.animation.export(),
      })
    },
    


  }
})
